package com.decade.qiyeshapan.controller;

import com.decade.qiyeshapan.service.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/redis")
public class RedisController {

    private static final Logger logger = LoggerFactory.getLogger(RedisController.class);

    @Autowired
    private RedisService redisService;

    @PostMapping("/set")
    public ResponseEntity<String> setData(@RequestParam String key, @RequestParam String value) {
        redisService.setDataToRedis(key, value);
        return ResponseEntity.ok("Data set successfully");
    }

    @GetMapping("/get")
    public ResponseEntity<Object> getData(@RequestParam String key) {
        logger.info("Testing TRACE_ID in controller");
        Object value = redisService.getDataFromRedis(key);
        return ResponseEntity.ok(value);
    }

    @DeleteMapping("/delete")
    public ResponseEntity<String> deleteData(@RequestParam String key) {
        redisService.setDataToRedis(key, null);
        return ResponseEntity.ok("Data deleted successfully");
    }
} 